const { ipcMain } = require("electron");
const m = require("./memo.js")

ipcMain.on("new-memo", (event, arg) => {
    m.creatMemo().then((data) => {
        event.reply("new-memo", true, data[0], data[1])
    }).catch((err) => {
        console.log("new-memo异常");
        console.log(err)
        event.reply("new-memo", false, err)
    })
})

ipcMain.on("rename-memo", (event, arg) => {
    m.reNameMemo(arg.id, arg.name).then((data) => {
        event.reply("rename-memo", true, data[0], data[1])
    }).catch((err) => {
        console.log("rename-memo异常");
        console.log(err)
        event.reply("rename-memo", false, err)
    })
})

ipcMain.on("change-content-memo", (event, arg) => {
    m.changeMemoContent(arg.id, arg.content).then((data) => {
        event.reply("change-content-memo", true, data[0], data[1])
    }).catch((err) => {
        console.log("change-content-memo异常");
        console.log(err)
        event.reply("change-content-memo", false, err)
    })
})

ipcMain.on("get-list-memo", (event, arg) => {
    m.getMemoList().then((data) => {
        event.reply("get-list-memo", true, data)
    }).catch((err) => {
        console.log("get-list-memo异常");
        console.log(err)
        event.reply("get-list-memo", false, err)
    })
})

ipcMain.on("delete-memo", (event, arg) => {
    m.deleteMemo(arg).then((data) => {
        event.reply("delete-memo", true, data)
    }).catch((err) => {
        console.log("delete-memo异常");
        console.log(err)
        event.reply("delete-memo", false, err)
    })
})

ipcMain.on("get-memo", (event, arg) => {
    m.getMemo(arg).then((data) => {
        event.reply("get-memo", true, data[0],data[1])
    }).catch((err) => {
        console.log("get-memo异常");
        console.log(err)
        event.reply("get-memo", false, err)
    })
})